#ifndef __CE_THREAD_H__
#define __CE_THREAD_H__

#include "ce_core.h"

typedef struct ce_thread_task_s ce_thread_task_t;

struct ce_thread_task_s {
    ce_list_node_t      qn;

    ce_atomic_t         id;

    void               *ctx;
    void              (*handler)(void *);
};

typedef struct {
    pthread_mutex_t     mtx;
    pthread_cond_t      cond;

    uint32_t            threadnum;

    ce_pool_t          *task_pool;
    ce_list_t           task_queue;
} ce_thread_pool_t;

ce_thread_pool_t *ce_thread_pool_create(uint32_t num);

ce_thread_task_t *ce_thread_task_get(ce_thread_pool_t *pool);
void ce_thread_task_post(ce_thread_pool_t *pool, ce_thread_task_t *task);

void ce_routine_start(ce_thread_pool_t *pool,
    void (*handler)(void *), void *ctx);

#endif
